package com.example.rmiserverdemo.server;


import com.example.rmiserverdemo.service.impl.MyRmiServiceImpl;
import com.sun.jndi.rmi.registry.ReferenceWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.naming.NamingException;
import javax.naming.Reference;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;

// ③服务绑定并启动监听
@Component
public class RmiServer {

    @Autowired
    private Registry registry;


    @PostConstruct
    public void init() throws RemoteException, AlreadyBoundException, NamingException {
        registry.bind("hello", new MyRmiServiceImpl());
        // 对象的工厂类名
        String className ="com.example.rmicommondemo.model.ReferenceObjectFactory";
        Reference reference = new Reference(className, className, "http://127.0.0.1:8083/rmiprovidedemo/class/get");
        ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);
        registry.bind("hello1", referenceWrapper);
    }

}